<?php
    include ("inc/global/global.inc.php");

if($_GET['action'] == 'mod'){
    $user = unserialize($_SESSION['user']);
    $id = $user->id;
    User::modifica_utente($id, $_POST['nome'], $_POST['cognome'], $_POST['username'], $_POST['oldPass'],$_POST['newPass']);
    Util::redirectLog();

}

  if($_GET["action"] == "modifica"){?>
    <div id="profilo">
        <form action="?action=mod" method="POST">
    <table width="400px">
        <tr>
            <td width="112px" height="154px" align="center" valign="top"> 
                <?php echo '<img src="'.$utente->immagine.'" width="150px">' ?>

            </td>
            <td width="305px" align="center" valign="top">
                    <table width="100%">
                        <tbody>
                            <tr>
                                <td height="17px" colspan="2" id="bar">
                                    <h2>Dati Personali</h2>
                                </td>
                            </tr>
                            <tr>
                                <td width="100px" align="right">
                                    <b>Stato:</b>
                                </td>
                                <td align="left">
                                <?php
                                    if(isset($_SESSION["user"])){
                                        echo "<font color=\"#008000\">ONLINE</font>";
                                    }
                                    else if(!isset($_SESSION["user"])){
                                        echo "<font color=\"red\">OFFLINE</font>";
                                    }
                                ?>
                                </td>
                            </tr>
                        <tr>
                            <td width="100px" align="right">
                                <b>Nome:</b>
                            </td>
                            <td align="left">
                                <input type="text" name="nome" value="<?php echo $utente->nome;?>" />
                                
                            </td>
                        </tr>
                        <tr>
                            <td width="100px" align="right">
                                <b>Cognome:</b>
                            </td>
                            <td align="left">
                                <input type="text" name="cognome" value="<?php echo $utente->cognome;?>" />
                            </td>
                        </tr>
                        <tr>
                            <td width="100px" align="right">
                                <b>E-mail:</b>
                            </td>
                            <td align="left">
                                 <?php
                                echo $utente->mail;
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td width="100px" align="right">
                                <b>Username:</b>
                            </td>
                            <td align="left">
                                <input type="text" name="username" value="<?php echo $utente->username;?>" />
                            </td>
                        </tr>
                        <tr>
                            <td width="100px" align="right">
                                <b>Old Pass:</b>
                            </td>
                            <td align="left">
                                <input type="password" name="oldPass" />
                            </td>
                        </tr>
                        <tr>
                            <td width="100px" align="right">
                                <b>New Pass:</b>
                            </td>
                            <td align="left">
                                <input type="password" name="newPass" />
                            </td>
                        </tr>
                        <tr>
                            <td></td>
                        <td><input type="submit" name="modifica" value="modifica i tuoi dati"></td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </table></form>
</div>
<?php
  }
  else{
?>
<div id="profilo">
    <table width="400px">
        <tr>
            <td width="112px" height="154px" align="center" valign="top">
                <?php echo '<img src="'.$utente->immagine.'" width="150px" >' ?>
               

            </td>
            <td width="305px" align="center" valign="top">
                    <table width="100%">
                        <tbody>
                            <tr>
                                <td height="17px" colspan="2" id="bar">
                                    <h2>Dati Personali</h2>
                                </td>
                            </tr>
                            <tr>
                                <td width="100px" align="right">
                                    <b>Stato:</b>
                                </td>
                                <td align="left">
                                <?php
                                    if(isset($_SESSION["user"])){
                                        echo "<font color=\"#008000\">ONLINE</font>";
                                    }
                                    else if(!isset($_SESSION["user"])){
                                        echo "<font color=\"red\">OFFLINE</font>";
                                    }
                                ?>
                                </td>
                            </tr>
                        <tr>
                            <td width="100px" align="right">
                                <b>Nome:</b>
                            </td>
                            <td align="left">
                                <?php
                                    echo $utente->nome;
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td width="100px" align="right">
                                <b>Cognome:</b>
                            </td>
                            <td align="left">
                                <?php
                                echo $utente->cognome;
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td width="100px" align="right">
                                <b>E-mail:</b>
                            </td>
                            <td align="left">
                                 <?php
                                echo $utente->mail;
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td width="100px" align="right">
                                <b>Username:</b>
                            </td>
                            <td align="left">
                                <?php
                                 echo $utente->username;
                                ?>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </table>
</div>
<?php
  }
  ?>